package com.wwj.controller;

import com.wwj.mapper.DepartmentMapper;
import com.wwj.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DepartmentController {

    @Autowired
    DepartmentMapper departmentMapper;

    // 查询全部部门
    @GetMapping("/getDepartments")
    public List<Department> getDepartments(){
        List<Department> departments = departmentMapper.getDepartments();
        for (Department department : departments) {
            System.out.println(department);

        }
        return departments;
    }

    // 查询全部部门
    @GetMapping("/getDepartment/{id}")
    public Department getDepartment(@PathVariable("id") Integer id){
        return departmentMapper.getDepartment(id);
    }

    @GetMapping("/addDepartment")
    public String addDepartment(){
        departmentMapper.addDepartment(new Department(6,"测试部"));
        return "增加成功";
    }

    @GetMapping("/updateDepartment")
    public String updateDepartment(){
        departmentMapper.updateDepartment(new Department(6,"xx"));
        return "修改成功";

    }

    @GetMapping("/deleteDepartment")
    public String deleteDepartment(){
        departmentMapper.deleteDepartment(6);
        return "修改成功";

    }


}
